package cn.micai.base.lambda.date;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 描述：1. Java Date Examples
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/22 20:20
 */
public class DateExample {

    public static void main(String [] args) throws ParseException {

        // Convert Date to String
        /*SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
        String date = sdf.format(new Date());
        System.out.println(date);*/

        // Convert String to Date
        /*SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
        String dateInString = "31-08-1982 10:20:56";
        Date date = sdf.parse(dateInString);
        System.out.println(date);*/

        // Get current date time
        /*SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        System.out.println(sdf.format(date));*/

        // Convert Calendar to Date
        Calendar instance = Calendar.getInstance();
        Date time = instance.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(time));

    }
}
